package com.blog.controller.frontpage;

import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blog.controller.base.BaseServlet;
import com.blog.entity.DiscussConstraintEntity;
import com.blog.entity.DiscussEntity;
import com.blog.entity.UserEntity;
import com.blog.entity.UserLoginEntity;
import com.blog.service.frontpage.DiscussService;
import com.blog.utils.TimeUtils;
import com.blog.utils.Util;
@WebServlet("/discussAjax")
public class DetailAjaxServlet extends BaseServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	
		
	String text = req.getParameter("text");
	String articleid = (String) req.getSession().getAttribute("titleid");
	UserLoginEntity user = (UserLoginEntity) req.getSession().getAttribute("user");
	Integer discuss_id = user.getUser_id();
	Timestamp time=Util.getTimestamp();
	
	DiscussEntity discuss = new DiscussEntity();
	if(text!=null&&!text.isEmpty()) {
		discuss.setDiscuss_content(text);
	}
	if(user!=null) {
		if(articleid!=null&&!articleid.isEmpty()) {
			discuss.setArticle_id(Integer.parseInt(articleid));
		}
	}
	if(discuss_id!=null) {
		discuss.setDiscuss_id(discuss_id);
	}
	discuss.setDiscuss_time(time);

	//1、向数据库插入一条语句
	DiscussService service = new DiscussService();
	int insertDiscuss = service.insertDiscuss(discuss);
		

	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	}
}
